package com.xcc.observerpattern.demo1;

/**
 * @Description: StatisticsDisplay
 * @Author: xiechuang
 * @Date: 2022/6/28
 */
public class StatisticsDisplay implements Observer, DisplayElement {

    // 温度值
    private float temperature;
    // 湿度值
    private float humidity;

    private Subject weatherData;

    public StatisticsDisplay(Subject weatherData) {
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    @Override
    public void display() {
        System.out.println("StatisticsDisplay 当前温度：" + temperature + "，湿度：" + humidity);
    }

    @Override
    public void update(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        display();
    }

}
